package com.yanq.liancar.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yanq.liancar.R;
import com.yanq.liancar.bean.OrderListBean;

import java.util.List;

public class BOrderListAdapter extends BaseQuickAdapter<OrderListBean.DataBean.OrderBean, BaseViewHolder> {
    public BOrderListAdapter(int layoutResId, @Nullable List<OrderListBean.DataBean.OrderBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, OrderListBean.DataBean.OrderBean item) {
        helper.setText(R.id.tv_orderNum, item.getOnum())
                .setText(R.id.tv_time, item.getPayDate())
                .setText(R.id.tv_time, item.getPayDate())
                .addOnClickListener(R.id.tv_type)
                .addOnClickListener(R.id.tv_refuse)
                .addOnClickListener(R.id.ll_content);

        TextView text_type = helper.getView(R.id.text_type);
        TextView tv_carType = helper.getView(R.id.tv_carType);
        TextView tv_wait = helper.getView(R.id.tv_wait);
        TextView tv_type = helper.getView(R.id.tv_type);
        TextView tv_price = helper.getView(R.id.tv_price);
        TextView tv_refuse = helper.getView(R.id.tv_refuse);
        TextView tv_orderType = helper.getView(R.id.tv_orderType);
        ImageView img_type = helper.getView(R.id.img_type);
        ImageView img_checked = helper.getView(R.id.img_checked);

        if (item.getOrderStatus() == 1) {
            tv_wait.setVisibility(View.VISIBLE);
            tv_type.setVisibility(View.GONE);
            tv_refuse.setVisibility(View.GONE);
            tv_orderType.setText("待支付");
            tv_wait.setText("等待支付");
        } else if (item.getOrderStatus() == 2) {
            tv_wait.setVisibility(View.GONE);
            tv_type.setVisibility(View.VISIBLE);
            tv_refuse.setVisibility(View.VISIBLE);
            tv_type.setText("接单");
            tv_orderType.setText("已支付");
        } else if (item.getOrderStatus() == 3) {
            tv_wait.setVisibility(View.VISIBLE);
            tv_type.setVisibility(View.VISIBLE);
            tv_refuse.setVisibility(View.GONE);
            tv_wait.setText("已拒单");
            tv_type.setText("查看原因");
        } else if (item.getOrderStatus() == 4) {
            tv_wait.setVisibility(View.GONE);
            tv_type.setVisibility(View.GONE);
            tv_refuse.setVisibility(View.GONE);
            tv_orderType.setText("已支付");
        } else if (item.getOrderStatus() == 5) {
            tv_wait.setVisibility(View.GONE);
            tv_type.setVisibility(View.GONE);
            tv_refuse.setVisibility(View.GONE);
            tv_orderType.setText("已完成");
        } else if (item.getOrderStatus() == 5) {
            tv_wait.setVisibility(View.GONE);
            tv_type.setVisibility(View.VISIBLE);
            tv_refuse.setVisibility(View.GONE);
            tv_type.setText("查看评价");
            tv_orderType.setText("已评价");
        }

        if (item.getServiceType() == 1) {
            text_type.setText("精致洗车");
            img_type.setImageResource(R.mipmap.xiche);
        } else if (item.getServiceType() == 2) {
            text_type.setText("标准洗车");
            img_type.setImageResource(R.mipmap.xiche2);
        } else if (item.getServiceType() == 3) {
            text_type.setText("美容养护");
            img_type.setImageResource(R.mipmap.meirong);
        } else if (item.getServiceType() == 4) {
            text_type.setText("到店保养");
            img_type.setImageResource(R.mipmap.bangyang);
        } else if (item.getServiceType() == 5) {
            text_type.setText("钣金喷漆");
            img_type.setImageResource(R.mipmap.penqi);
        } else if (item.getServiceType() == 6) {
            text_type.setText("代办服务");
            img_type.setImageResource(R.mipmap.daiban);
        } else if (item.getServiceType() == 7){
            text_type.setText("全车打蜡");
            img_type.setImageResource(R.mipmap.fuwu_dala);
        }else if (item.getServiceType() == 80){
            text_type.setText("快速洗车");
            img_type.setImageResource(R.mipmap.xiche);
        }else  if (item.getServiceType() == 90){
            text_type.setText("精准洗车");
            img_type.setImageResource(R.mipmap.xiche);
        }

        if (item.getCarType() == 0) {
            tv_carType.setText("小型汽车");
        } else if (item.getCarType() == 1) {
            tv_carType.setText("大型汽车");
        } else {
            tv_carType.setText("SUV汽车");
        }

        if (item.getPayType() == 0) {
            tv_price.setText("线下支付");
        } else {
            tv_price.setText("¥" + item.getAllPrice());
        }

        if (item.getCc() == null) {
            helper.setText(R.id.tv_daijinquan, "无");
        } else {
            helper.setText(R.id.tv_daijinquan, "¥ " + item.getCc().getCashcoupon_value());
        }

        if (item.getSv() == null) {
            helper.setText(R.id.tv_fuwuquan, "无");
        } else {
            helper.setText(R.id.tv_fuwuquan, item.getSv().getService_content());
        }

        if (item.isGone()){
            img_checked.setVisibility(View.VISIBLE);
        }else {
            img_checked.setVisibility(View.GONE);
        }

        if (item.isChecked()) {
            img_checked.setImageResource(R.drawable.checked);
        } else {
            img_checked.setImageResource(R.drawable.unchecked);
        }
    }

}

